import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: ' ', tag:'是否生成终止报告单',	name: 'termination', 	full:true, 	type:'checkbox', value:0  },
			{ label: '异常原因类型',					name: 'abnormal_type', 	full:true, 	type: 'select', required:true, idStr:'code', onValue:({ value, rows, ref }) => {
				ref.setValue({ reason: +value !== 62051 ? rows['name'] : '' })
			} },
			{ label: '原因',        				name: 'reason', 		full:true, 	type:'textarea', required:true },
		]
	}
	
	open = param => {
		this.modal.open({ formRef: this.formRef })
		this.formRef.setValue({termination:0})
		this.submit = param
		this.getModalSelect()
	}
	
	// 获取弹窗下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'abnormal_type', ()=>{
			$cache.then( async f => {
				// 异常原因类型
				$fn.setRow(formData, 'abnormal_type', await f.getDicCache({ code: 62050 }))
				this.setState({ formData })
			})
		})
	}
	
	render(){
		const { api } = this.props
		return FormModal.call(this,{ title: '报告单终止', labelWidth:'s7', width:600, clear:true, api})
	}
}

export default Index